﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;

namespace Chenxin.Lib.Business.DAL
{
    /// <summary>
    /// 数据访问类t_Contract_CommisionInfo。
    /// </summary>
    public class t_Contract_CommisionInfo
    {
        public t_Contract_CommisionInfo()
        { }
        #region  成员方法

        public static void ExcuteSql(string strSql)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.ExecuteNonQuery(dbCommand);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static void Add(Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_Contract_CommisionInfo(");
            strSql.Append("ContractId,VRealCommisionFinal,BRealCommisionFinal,VCommisionFinal,BCommisionFinal,VConsultingFinal,BConsultingFinal,VCommisionGeted,BCommisionGeted,VCommisionGetedPayed,BCommisionGetedPayed,VConsultingPayed,BConsultingPayed,CanGetSaleMoney,GetedSaleMoney,PayedSaleMoney,CanGetTax,GetedTax,PayedTax,UpdateTime,UpdateEmployeeId,UpdateEmployee,VSTDiscountFinal,BSTDiscountFinal,FixDiscountFinal,DiscountRateFinal)");

            strSql.Append(" values (");
            strSql.Append("@ContractId,@VRealCommisionFinal,@BRealCommisionFinal,@VCommisionFinal,@BCommisionFinal,@VConsultingFinal,@BConsultingFinal,@VCommisionGeted,@BCommisionGeted,@VCommisionGetedPayed,@BCommisionGetedPayed,@VConsultingPayed,@BConsultingPayed,@CanGetSaleMoney,@GetedSaleMoney,@PayedSaleMoney,@CanGetTax,@GetedTax,@PayedTax,@UpdateTime,@UpdateEmployeeId,@UpdateEmployee,@VSTDiscountFinal,@BSTDiscountFinal,@FixDiscountFinal,@DiscountRateFinal)");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ContractId", DbType.Guid, model.ContractId);
            db.AddInParameter(dbCommand, "VRealCommisionFinal", DbType.Decimal, model.VRealCommisionFinal);
            db.AddInParameter(dbCommand, "BRealCommisionFinal", DbType.Decimal, model.BRealCommisionFinal);
            db.AddInParameter(dbCommand, "VCommisionFinal", DbType.Decimal, model.VCommisionFinal);
            db.AddInParameter(dbCommand, "BCommisionFinal", DbType.Decimal, model.BCommisionFinal);
            db.AddInParameter(dbCommand, "VConsultingFinal", DbType.Decimal, model.VConsultingFinal);
            db.AddInParameter(dbCommand, "BConsultingFinal", DbType.Decimal, model.BConsultingFinal);
            db.AddInParameter(dbCommand, "VCommisionGeted", DbType.Decimal, model.VCommisionGeted);
            db.AddInParameter(dbCommand, "BCommisionGeted", DbType.Decimal, model.BCommisionGeted);
            db.AddInParameter(dbCommand, "VCommisionGetedPayed", DbType.Decimal, model.VCommisionGetedPayed);
            db.AddInParameter(dbCommand, "BCommisionGetedPayed", DbType.Decimal, model.BCommisionGetedPayed);
            db.AddInParameter(dbCommand, "VConsultingPayed", DbType.Decimal, model.VConsultingPayed);
            db.AddInParameter(dbCommand, "BConsultingPayed", DbType.Decimal, model.BConsultingPayed);
            db.AddInParameter(dbCommand, "CanGetSaleMoney", DbType.Decimal, model.CanGetSaleMoney);
            db.AddInParameter(dbCommand, "GetedSaleMoney", DbType.Decimal, model.GetedSaleMoney);
            db.AddInParameter(dbCommand, "PayedSaleMoney", DbType.Decimal, model.PayedSaleMoney);
            db.AddInParameter(dbCommand, "CanGetTax", DbType.Decimal, model.CanGetTax);
            db.AddInParameter(dbCommand, "GetedTax", DbType.Decimal, model.GetedTax);
            db.AddInParameter(dbCommand, "PayedTax", DbType.Decimal, model.PayedTax);
            db.AddInParameter(dbCommand, "UpdateTime", DbType.DateTime, model.UpdateTime);
            db.AddInParameter(dbCommand, "UpdateEmployeeId", DbType.Guid, model.UpdateEmployeeId);
            db.AddInParameter(dbCommand, "UpdateEmployee", DbType.AnsiString, model.UpdateEmployee);
            db.AddInParameter(dbCommand, "VSTDiscountFinal", DbType.Decimal, model.VSTDiscountFinal);
            db.AddInParameter(dbCommand, "BSTDiscountFinal", DbType.Decimal, model.BSTDiscountFinal);
            db.AddInParameter(dbCommand, "FixDiscountFinal", DbType.Decimal, model.FixDiscountFinal);
            db.AddInParameter(dbCommand, "DiscountRateFinal", DbType.Decimal, model.DiscountRateFinal);
            db.ExecuteNonQuery(dbCommand);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static void Update(Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_Contract_CommisionInfo set ");
            strSql.Append("VRealCommisionFinal=@VRealCommisionFinal,");
            strSql.Append("BRealCommisionFinal=@BRealCommisionFinal,");
            strSql.Append("VCommisionFinal=@VCommisionFinal,");
            strSql.Append("BCommisionFinal=@BCommisionFinal,");
            strSql.Append("VConsultingFinal=@VConsultingFinal,");
            strSql.Append("BConsultingFinal=@BConsultingFinal,");
            strSql.Append("VCommisionGeted=@VCommisionGeted,");
            strSql.Append("BCommisionGeted=@BCommisionGeted,");
            strSql.Append("VCommisionGetedPayed=@VCommisionGetedPayed,");
            strSql.Append("BCommisionGetedPayed=@BCommisionGetedPayed,");
            strSql.Append("VConsultingPayed=@VConsultingPayed,");
            strSql.Append("BConsultingPayed=@BConsultingPayed,");
            strSql.Append("CanGetSaleMoney=@CanGetSaleMoney,");
            strSql.Append("GetedSaleMoney=@GetedSaleMoney,");
            strSql.Append("PayedSaleMoney=@PayedSaleMoney,");
            strSql.Append("CanGetTax=@CanGetTax,");
            strSql.Append("GetedTax=@GetedTax,");
            strSql.Append("PayedTax=@PayedTax,");
            strSql.Append("UpdateTime=@UpdateTime,");
            strSql.Append("UpdateEmployeeId=@UpdateEmployeeId,");
            strSql.Append("UpdateEmployee=@UpdateEmployee,");
            strSql.Append("VSTDiscountFinal=@VSTDiscountFinal,");
            strSql.Append("BSTDiscountFinal=@BSTDiscountFinal,");
            strSql.Append("FixDiscountFinal=@FixDiscountFinal,");
            strSql.Append("DiscountRateFinal=@DiscountRateFinal");
            strSql.Append(" where ContractId=@ContractId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ContractId", DbType.Guid, model.ContractId);
            db.AddInParameter(dbCommand, "VRealCommisionFinal", DbType.Decimal, model.VRealCommisionFinal);
            db.AddInParameter(dbCommand, "BRealCommisionFinal", DbType.Decimal, model.BRealCommisionFinal);
            db.AddInParameter(dbCommand, "VCommisionFinal", DbType.Decimal, model.VCommisionFinal);
            db.AddInParameter(dbCommand, "BCommisionFinal", DbType.Decimal, model.BCommisionFinal);
            db.AddInParameter(dbCommand, "VConsultingFinal", DbType.Decimal, model.VConsultingFinal);
            db.AddInParameter(dbCommand, "BConsultingFinal", DbType.Decimal, model.BConsultingFinal);
            db.AddInParameter(dbCommand, "VCommisionGeted", DbType.Decimal, model.VCommisionGeted);
            db.AddInParameter(dbCommand, "BCommisionGeted", DbType.Decimal, model.BCommisionGeted);
            db.AddInParameter(dbCommand, "VCommisionGetedPayed", DbType.Decimal, model.VCommisionGetedPayed);
            db.AddInParameter(dbCommand, "BCommisionGetedPayed", DbType.Decimal, model.BCommisionGetedPayed);
            db.AddInParameter(dbCommand, "VConsultingPayed", DbType.Decimal, model.VConsultingPayed);
            db.AddInParameter(dbCommand, "BConsultingPayed", DbType.Decimal, model.BConsultingPayed);
            db.AddInParameter(dbCommand, "CanGetSaleMoney", DbType.Decimal, model.CanGetSaleMoney);
            db.AddInParameter(dbCommand, "GetedSaleMoney", DbType.Decimal, model.GetedSaleMoney);
            db.AddInParameter(dbCommand, "PayedSaleMoney", DbType.Decimal, model.PayedSaleMoney);
            db.AddInParameter(dbCommand, "CanGetTax", DbType.Decimal, model.CanGetTax);
            db.AddInParameter(dbCommand, "GetedTax", DbType.Decimal, model.GetedTax);
            db.AddInParameter(dbCommand, "PayedTax", DbType.Decimal, model.PayedTax);
            db.AddInParameter(dbCommand, "UpdateTime", DbType.DateTime, model.UpdateTime);
            db.AddInParameter(dbCommand, "UpdateEmployeeId", DbType.Guid, model.UpdateEmployeeId);
            db.AddInParameter(dbCommand, "UpdateEmployee", DbType.AnsiString, model.UpdateEmployee);
            db.AddInParameter(dbCommand, "VSTDiscountFinal", DbType.Decimal, model.VSTDiscountFinal);
            db.AddInParameter(dbCommand, "BSTDiscountFinal", DbType.Decimal, model.BSTDiscountFinal);
            db.AddInParameter(dbCommand, "FixDiscountFinal", DbType.Decimal, model.FixDiscountFinal);
            db.AddInParameter(dbCommand, "DiscountRateFinal", DbType.Decimal, model.DiscountRateFinal);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static void Delete(Guid ContractId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_Contract_CommisionInfo ");
            strSql.Append(" where ContractId=@ContractId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ContractId", DbType.Guid, ContractId);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo GetModel(Guid ContractId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ContractId,VRealCommisionFinal,BRealCommisionFinal,VCommisionFinal,BCommisionFinal,VConsultingFinal,BConsultingFinal,VCommisionGeted,BCommisionGeted,VCommisionGetedPayed,BCommisionGetedPayed,VConsultingPayed,BConsultingPayed,CanGetSaleMoney,GetedSaleMoney,PayedSaleMoney,CanGetTax,GetedTax,PayedTax,UpdateTime,UpdateEmployeeId,UpdateEmployee,VSTDiscountFinal,BSTDiscountFinal,FixDiscountFinal,DiscountRateFinal from t_Contract_CommisionInfo ");
            strSql.Append(" where ContractId=@ContractId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ContractId", DbType.Guid, ContractId);
            Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ContractId,VRealCommisionFinal,BRealCommisionFinal,VCommisionFinal,BCommisionFinal,VConsultingFinal,BConsultingFinal,VCommisionGeted,BCommisionGeted,VCommisionGetedPayed,BCommisionGetedPayed,VConsultingPayed,BConsultingPayed,CanGetSaleMoney,GetedSaleMoney,PayedSaleMoney,CanGetTax,GetedTax,PayedTax,UpdateTime,UpdateEmployeeId,UpdateEmployee,VSTDiscountFinal,BSTDiscountFinal,FixDiscountFinal,DiscountRateFinal ");
            strSql.Append(" FROM t_Contract_CommisionInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public static DataSet GetList(int PageIndex, int PageSize, String OrderField, string TableName, string StrWhere, string FieldList, string TableFieldList, bool DoCount)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            DbCommand dbCommand = db.GetStoredProcCommand("PagerMultiTable");
            db.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
            db.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            db.AddInParameter(dbCommand, "OrderField", DbType.AnsiString, OrderField);
            db.AddInParameter(dbCommand, "TableName", DbType.AnsiString, TableName);
            db.AddInParameter(dbCommand, "StrWhere", DbType.AnsiString, StrWhere);
            db.AddInParameter(dbCommand, "FieldList", DbType.AnsiString, FieldList);
            db.AddInParameter(dbCommand, "TableFieldList", DbType.AnsiString, TableFieldList);
            db.AddInParameter(dbCommand, "DoCount", DbType.Boolean, DoCount);
            return db.ExecuteDataSet(dbCommand);
        }

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public static List<Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ContractId,VRealCommisionFinal,BRealCommisionFinal,VCommisionFinal,BCommisionFinal,VConsultingFinal,BConsultingFinal,VCommisionGeted,BCommisionGeted,VCommisionGetedPayed,BCommisionGetedPayed,VConsultingPayed,BConsultingPayed,CanGetSaleMoney,GetedSaleMoney,PayedSaleMoney,CanGetTax,GetedTax,PayedTax,UpdateTime,UpdateEmployeeId,UpdateEmployee,VSTDiscountFinal,BSTDiscountFinal,FixDiscountFinal,DiscountRateFinal ");
            strSql.Append(" FROM t_Contract_CommisionInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo> list = new List<Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo>();
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return list;
        }


        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public static Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo ReaderBind(IDataReader dataReader)
        {
            Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo model = new Chenxin.Lib.Business.Entity.t_Contract_CommisionInfo();
            object ojb;
            ojb = dataReader["ContractId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ContractId = new Guid(ojb.ToString());
            }
            ojb = dataReader["VRealCommisionFinal"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.VRealCommisionFinal = (decimal)ojb;
            }
            ojb = dataReader["BRealCommisionFinal"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BRealCommisionFinal = (decimal)ojb;
            }
            ojb = dataReader["VCommisionFinal"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.VCommisionFinal = (decimal)ojb;
            }
            ojb = dataReader["BCommisionFinal"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BCommisionFinal = (decimal)ojb;
            }
            ojb = dataReader["VConsultingFinal"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.VConsultingFinal = (decimal)ojb;
            }
            ojb = dataReader["BConsultingFinal"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BConsultingFinal = (decimal)ojb;
            }
            ojb = dataReader["VCommisionGeted"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.VCommisionGeted = (decimal)ojb;
            }
            ojb = dataReader["BCommisionGeted"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BCommisionGeted = (decimal)ojb;
            }
            ojb = dataReader["VCommisionGetedPayed"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.VCommisionGetedPayed = (decimal)ojb;
            }
            ojb = dataReader["BCommisionGetedPayed"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BCommisionGetedPayed = (decimal)ojb;
            }
            ojb = dataReader["VConsultingPayed"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.VConsultingPayed = (decimal)ojb;
            }
            ojb = dataReader["BConsultingPayed"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BConsultingPayed = (decimal)ojb;
            }
            ojb = dataReader["CanGetSaleMoney"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanGetSaleMoney = (decimal)ojb;
            }
            ojb = dataReader["GetedSaleMoney"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.GetedSaleMoney = (decimal)ojb;
            }
            ojb = dataReader["PayedSaleMoney"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.PayedSaleMoney = (decimal)ojb;
            }
            ojb = dataReader["CanGetTax"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanGetTax = (decimal)ojb;
            }
            ojb = dataReader["GetedTax"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.GetedTax = (decimal)ojb;
            }
            ojb = dataReader["PayedTax"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.PayedTax = (decimal)ojb;
            }
            ojb = dataReader["UpdateTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UpdateTime = (DateTime)ojb;
            }
            ojb = dataReader["UpdateEmployeeId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UpdateEmployeeId = new Guid(ojb.ToString());
            }
            model.UpdateEmployee = dataReader["UpdateEmployee"].ToString();
            ojb = dataReader["VSTDiscountFinal"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.VSTDiscountFinal = (decimal)ojb;
            }
            ojb = dataReader["BSTDiscountFinal"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BSTDiscountFinal = (decimal)ojb;
            }
            ojb = dataReader["FixDiscountFinal"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.FixDiscountFinal = (decimal)ojb;
            }
            ojb = dataReader["DiscountRateFinal"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.DiscountRateFinal = (decimal)ojb;
            }
            return model;
        }

        /// <summary>
        /// 获取佣金信息
        /// </summary>
        public static DataSet GetCommisionInfo(string ContractId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendFormat("SELECT * FROM GetCommisionInfo('{0}')",ContractId);
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        #endregion  成员方法
    }
}

